{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "view-in-github"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/bkkaggle/pytorch-CycleGAN-and-pix2pix/blob/master/pix2pix.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "7wNjDKdQy35h"
   },
   "source": [
    "# Install"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "TRm-USlsHgEV"
   },
   "outputs": [],
   "source": [
    "#!git clone https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Pt3igws3eiVp"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "#os.chdir('pytorch-CycleGAN-and-pix2pix/')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "z1EySlOXwwoa"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: torch>=0.4.1 in /home/zhiwei/miniconda3/lib/python3.7/site-packages (from -r requirements.txt (line 1)) (1.4.0)\n",
      "Requirement already satisfied: torchvision>=0.2.1 in /home/zhiwei/miniconda3/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (0.5.0)\n",
      "Collecting dominate>=2.3.1\n",
      "\u001b[33m  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError(\"HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out. (read timeout=15)\")': /packages/4f/e6/794a119963b7cfe4bd41177c8f9d4195fe901652f04189fbd2edf513c7b2/dominate-2.5.1-py2.py3-none-any.whl\u001b[0m\n",
      "  Downloading https://files.pythonhosted.org/packages/4f/e6/794a119963b7cfe4bd41177c8f9d4195fe901652f04189fbd2edf513c7b2/dominate-2.5.1-py2.py3-none-any.whl\n",
      "Collecting visdom>=0.1.8.3\n",
      "\u001b[?25l  Downloading https://files.pythonhosted.org/packages/c9/75/e078f5a2e1df7e0d3044749089fc2823e62d029cc027ed8ae5d71fafcbdc/visdom-0.1.8.9.tar.gz (676kB)\n",
      "\u001b[K     |██▍                             | 51kB 5.6kB/s eta 0:01:53\u001b[31mERROR: Exception:\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py\", line 313, in recv_into\n",
      "    return self.connection.recv_into(*args, **kwargs)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/OpenSSL/SSL.py\", line 1822, in recv_into\n",
      "    self._raise_ssl_error(self._ssl, result)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/OpenSSL/SSL.py\", line 1622, in _raise_ssl_error\n",
      "    raise WantReadError()\n",
      "OpenSSL.SSL.WantReadError\n",
      "\n",
      "During handling of the above exception, another exception occurred:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py\", line 425, in _error_catcher\n",
      "    yield\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py\", line 507, in read\n",
      "    data = self._fp.read(amt) if not fp_closed else b\"\"\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/cachecontrol/filewrapper.py\", line 62, in read\n",
      "    data = self.__fp.read(amt)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/http/client.py\", line 457, in read\n",
      "    n = self.readinto(b)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/http/client.py\", line 501, in readinto\n",
      "    n = self.fp.readinto(b)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/socket.py\", line 589, in readinto\n",
      "    return self._sock.recv_into(b)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py\", line 326, in recv_into\n",
      "    raise timeout(\"The read operation timed out\")\n",
      "socket.timeout: The read operation timed out\n",
      "\n",
      "During handling of the above exception, another exception occurred:\n",
      "\n",
      "Traceback (most recent call last):\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/cli/base_command.py\", line 153, in _main\n",
      "    status = self.run(options, args)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/commands/install.py\", line 382, in run\n",
      "    resolver.resolve(requirement_set)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/legacy_resolve.py\", line 201, in resolve\n",
      "    self._resolve_one(requirement_set, req)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/legacy_resolve.py\", line 365, in _resolve_one\n",
      "    abstract_dist = self._get_abstract_dist_for(req_to_install)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/legacy_resolve.py\", line 313, in _get_abstract_dist_for\n",
      "    req, self.session, self.finder, self.require_hashes\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/operations/prepare.py\", line 194, in prepare_linked_requirement\n",
      "    progress_bar=self.progress_bar\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/download.py\", line 465, in unpack_url\n",
      "    progress_bar=progress_bar\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/download.py\", line 316, in unpack_http_url\n",
      "    progress_bar)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/download.py\", line 551, in _download_http_url\n",
      "    _download_url(resp, link, content_file, hashes, progress_bar)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/download.py\", line 253, in _download_url\n",
      "    hashes.check_against_chunks(downloaded_chunks)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/utils/hashes.py\", line 80, in check_against_chunks\n",
      "    for chunk in chunks:\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/download.py\", line 223, in written_chunks\n",
      "    for chunk in chunks:\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/utils/ui.py\", line 160, in iter\n",
      "    for x in it:\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_internal/download.py\", line 212, in resp_read\n",
      "    decode_content=False):\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py\", line 564, in stream\n",
      "    data = self.read(amt=amt, decode_content=decode_content)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py\", line 529, in read\n",
      "    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/contextlib.py\", line 130, in __exit__\n",
      "    self.gen.throw(type, value, traceback)\n",
      "  File \"/home/zhiwei/miniconda3/lib/python3.7/site-packages/pip/_vendor/urllib3/response.py\", line 430, in _error_catcher\n",
      "    raise ReadTimeoutError(self._pool, None, \"Read timed out.\")\n",
      "pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.\u001b[0m\n"
     ]
    }
   ],
   "source": [
    "!pip install -r requirements.txt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "8daqlgVhw29P"
   },
   "source": [
    "# Datasets\n",
    "\n",
    "Download one of the official datasets with:\n",
    "\n",
    "-   `bash ./datasets/download_pix2pix_dataset.sh [cityscapes, night2day, edges2handbags, edges2shoes, facades, maps]`\n",
    "\n",
    "Or use your own dataset by creating the appropriate folders and adding in the images. Follow the instructions [here](https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/docs/datasets.md#pix2pix-datasets)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "vrdOettJxaCc"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Specified [facades]\n",
      "WARNING: timestamping does nothing in combination with -O. See the manual\n",
      "for details.\n",
      "\n",
      "--2020-03-19 18:07:05--  http://efrosgans.eecs.berkeley.edu/pix2pix/datasets/facades.tar.gz\n",
      "Resolving efrosgans.eecs.berkeley.edu (efrosgans.eecs.berkeley.edu)... 128.32.189.73\n",
      "Connecting to efrosgans.eecs.berkeley.edu (efrosgans.eecs.berkeley.edu)|128.32.189.73|:80... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 30168306 (29M) [application/x-gzip]\n",
      "Saving to: ‘./datasets/facades.tar.gz’\n",
      "\n",
      "./datasets/facades. 100%[===================>]  28.77M  9.44KB/s    in 41m 8s  \n",
      "\n",
      "2020-03-19 18:48:14 (11.9 KB/s) - ‘./datasets/facades.tar.gz’ saved [30168306/30168306]\n",
      "\n",
      "facades/\n",
      "facades/test/\n",
      "facades/test/27.jpg\n",
      "facades/test/5.jpg\n",
      "facades/test/72.jpg\n",
      "facades/test/1.jpg\n",
      "facades/test/10.jpg\n",
      "facades/test/100.jpg\n",
      "facades/test/101.jpg\n",
      "facades/test/102.jpg\n",
      "facades/test/103.jpg\n",
      "facades/test/104.jpg\n",
      "facades/test/105.jpg\n",
      "facades/test/106.jpg\n",
      "facades/test/11.jpg\n",
      "facades/test/12.jpg\n",
      "facades/test/13.jpg\n",
      "facades/test/14.jpg\n",
      "facades/test/15.jpg\n",
      "facades/test/16.jpg\n",
      "facades/test/17.jpg\n",
      "facades/test/18.jpg\n",
      "facades/test/19.jpg\n",
      "facades/test/2.jpg\n",
      "facades/test/20.jpg\n",
      "facades/test/21.jpg\n",
      "facades/test/22.jpg\n",
      "facades/test/23.jpg\n",
      "facades/test/24.jpg\n",
      "facades/test/25.jpg\n",
      "facades/test/26.jpg\n",
      "facades/test/50.jpg\n",
      "facades/test/51.jpg\n",
      "facades/test/52.jpg\n",
      "facades/test/53.jpg\n",
      "facades/test/54.jpg\n",
      "facades/test/55.jpg\n",
      "facades/test/56.jpg\n",
      "facades/test/57.jpg\n",
      "facades/test/58.jpg\n",
      "facades/test/59.jpg\n",
      "facades/test/6.jpg\n",
      "facades/test/60.jpg\n",
      "facades/test/61.jpg\n",
      "facades/test/62.jpg\n",
      "facades/test/63.jpg\n",
      "facades/test/64.jpg\n",
      "facades/test/65.jpg\n",
      "facades/test/66.jpg\n",
      "facades/test/67.jpg\n",
      "facades/test/68.jpg\n",
      "facades/test/69.jpg\n",
      "facades/test/7.jpg\n",
      "facades/test/70.jpg\n",
      "facades/test/71.jpg\n",
      "facades/test/73.jpg\n",
      "facades/test/74.jpg\n",
      "facades/test/75.jpg\n",
      "facades/test/76.jpg\n",
      "facades/test/77.jpg\n",
      "facades/test/78.jpg\n",
      "facades/test/79.jpg\n",
      "facades/test/8.jpg\n",
      "facades/test/80.jpg\n",
      "facades/test/81.jpg\n",
      "facades/test/82.jpg\n",
      "facades/test/83.jpg\n",
      "facades/test/84.jpg\n",
      "facades/test/85.jpg\n",
      "facades/test/86.jpg\n",
      "facades/test/87.jpg\n",
      "facades/test/88.jpg\n",
      "facades/test/89.jpg\n",
      "facades/test/9.jpg\n",
      "facades/test/90.jpg\n",
      "facades/test/91.jpg\n",
      "facades/test/92.jpg\n",
      "facades/test/93.jpg\n",
      "facades/test/94.jpg\n",
      "facades/test/95.jpg\n",
      "facades/test/96.jpg\n",
      "facades/test/97.jpg\n",
      "facades/test/98.jpg\n",
      "facades/test/99.jpg\n",
      "facades/test/28.jpg\n",
      "facades/test/29.jpg\n",
      "facades/test/3.jpg\n",
      "facades/test/30.jpg\n",
      "facades/test/31.jpg\n",
      "facades/test/32.jpg\n",
      "facades/test/33.jpg\n",
      "facades/test/34.jpg\n",
      "facades/test/35.jpg\n",
      "facades/test/36.jpg\n",
      "facades/test/37.jpg\n",
      "facades/test/38.jpg\n",
      "facades/test/39.jpg\n",
      "facades/test/4.jpg\n",
      "facades/test/40.jpg\n",
      "facades/test/41.jpg\n",
      "facades/test/42.jpg\n",
      "facades/test/43.jpg\n",
      "facades/test/44.jpg\n",
      "facades/test/45.jpg\n",
      "facades/test/46.jpg\n",
      "facades/test/47.jpg\n",
      "facades/test/48.jpg\n",
      "facades/test/49.jpg\n",
      "facades/train/\n",
      "facades/train/1.jpg\n",
      "facades/train/10.jpg\n",
      "facades/train/100.jpg\n",
      "facades/train/101.jpg\n",
      "facades/train/102.jpg\n",
      "facades/train/103.jpg\n",
      "facades/train/104.jpg\n",
      "facades/train/105.jpg\n",
      "facades/train/106.jpg\n",
      "facades/train/107.jpg\n",
      "facades/train/108.jpg\n",
      "facades/train/109.jpg\n",
      "facades/train/11.jpg\n",
      "facades/train/110.jpg\n",
      "facades/train/111.jpg\n",
      "facades/train/112.jpg\n",
      "facades/train/113.jpg\n",
      "facades/train/114.jpg\n",
      "facades/train/115.jpg\n",
      "facades/train/116.jpg\n",
      "facades/train/117.jpg\n",
      "facades/train/118.jpg\n",
      "facades/train/119.jpg\n",
      "facades/train/12.jpg\n",
      "facades/train/120.jpg\n",
      "facades/train/121.jpg\n",
      "facades/train/122.jpg\n",
      "facades/train/123.jpg\n",
      "facades/train/124.jpg\n",
      "facades/train/125.jpg\n",
      "facades/train/126.jpg\n",
      "facades/train/309.jpg\n",
      "facades/train/31.jpg\n",
      "facades/train/310.jpg\n",
      "facades/train/311.jpg\n",
      "facades/train/312.jpg\n",
      "facades/train/313.jpg\n",
      "facades/train/314.jpg\n",
      "facades/train/315.jpg\n",
      "facades/train/316.jpg\n",
      "facades/train/317.jpg\n",
      "facades/train/318.jpg\n",
      "facades/train/319.jpg\n",
      "facades/train/32.jpg\n",
      "facades/train/320.jpg\n",
      "facades/train/321.jpg\n",
      "facades/train/322.jpg\n",
      "facades/train/323.jpg\n",
      "facades/train/324.jpg\n",
      "facades/train/325.jpg\n",
      "facades/train/326.jpg\n",
      "facades/train/327.jpg\n",
      "facades/train/328.jpg\n",
      "facades/train/329.jpg\n",
      "facades/train/390.jpg\n",
      "facades/train/391.jpg\n",
      "facades/train/392.jpg\n",
      "facades/train/393.jpg\n",
      "facades/train/394.jpg\n",
      "facades/train/395.jpg\n",
      "facades/train/396.jpg\n",
      "facades/train/397.jpg\n",
      "facades/train/398.jpg\n",
      "facades/train/399.jpg\n",
      "facades/train/4.jpg\n",
      "facades/train/40.jpg\n",
      "facades/train/400.jpg\n",
      "facades/train/41.jpg\n",
      "facades/train/42.jpg\n",
      "facades/train/43.jpg\n",
      "facades/train/44.jpg\n",
      "facades/train/45.jpg\n",
      "facades/train/46.jpg\n",
      "facades/train/47.jpg\n",
      "facades/train/48.jpg\n",
      "facades/train/49.jpg\n",
      "facades/train/5.jpg\n",
      "facades/train/50.jpg\n",
      "facades/train/51.jpg\n",
      "facades/train/52.jpg\n",
      "facades/train/53.jpg\n",
      "facades/train/54.jpg\n",
      "facades/train/55.jpg\n",
      "facades/train/56.jpg\n",
      "facades/train/57.jpg\n",
      "facades/train/58.jpg\n",
      "facades/train/59.jpg\n",
      "facades/train/6.jpg\n",
      "facades/train/60.jpg\n",
      "facades/train/61.jpg\n",
      "facades/train/222.jpg\n",
      "facades/train/223.jpg\n",
      "facades/train/224.jpg\n",
      "facades/train/225.jpg\n",
      "facades/train/226.jpg\n",
      "facades/train/227.jpg\n",
      "facades/train/228.jpg\n",
      "facades/train/229.jpg\n",
      "facades/train/23.jpg\n",
      "facades/train/230.jpg\n",
      "facades/train/231.jpg\n",
      "facades/train/232.jpg\n",
      "facades/train/233.jpg\n",
      "facades/train/234.jpg\n",
      "facades/train/235.jpg\n",
      "facades/train/236.jpg\n",
      "facades/train/237.jpg\n",
      "facades/train/238.jpg\n",
      "facades/train/239.jpg\n",
      "facades/train/24.jpg\n",
      "facades/train/240.jpg\n",
      "facades/train/241.jpg\n",
      "facades/train/242.jpg\n",
      "facades/train/243.jpg\n",
      "facades/train/244.jpg\n",
      "facades/train/245.jpg\n",
      "facades/train/156.jpg\n",
      "facades/train/157.jpg\n",
      "facades/train/158.jpg\n",
      "facades/train/159.jpg\n",
      "facades/train/16.jpg\n",
      "facades/train/160.jpg\n",
      "facades/train/161.jpg\n",
      "facades/train/162.jpg\n",
      "facades/train/163.jpg\n",
      "facades/train/164.jpg\n",
      "facades/train/165.jpg\n",
      "facades/train/166.jpg\n",
      "facades/train/167.jpg\n",
      "facades/train/168.jpg\n",
      "facades/train/169.jpg\n",
      "facades/train/17.jpg\n",
      "facades/train/170.jpg\n",
      "facades/train/171.jpg\n",
      "facades/train/172.jpg\n",
      "facades/train/173.jpg\n",
      "facades/train/174.jpg\n",
      "facades/train/175.jpg\n",
      "facades/train/176.jpg\n",
      "facades/train/177.jpg\n",
      "facades/train/178.jpg\n",
      "facades/train/179.jpg\n",
      "facades/train/18.jpg\n",
      "facades/train/180.jpg\n",
      "facades/train/181.jpg\n",
      "facades/train/182.jpg\n",
      "facades/train/183.jpg\n",
      "facades/train/184.jpg\n",
      "facades/train/185.jpg\n",
      "facades/train/186.jpg\n",
      "facades/train/187.jpg\n",
      "facades/train/188.jpg\n",
      "facades/train/189.jpg\n",
      "facades/train/19.jpg\n",
      "facades/train/127.jpg\n",
      "facades/train/155.jpg\n",
      "facades/train/190.jpg\n",
      "facades/train/221.jpg\n",
      "facades/train/246.jpg\n",
      "facades/train/27.jpg\n",
      "facades/train/29.jpg\n",
      "facades/train/308.jpg\n",
      "facades/train/33.jpg\n",
      "facades/train/350.jpg\n",
      "facades/train/370.jpg\n",
      "facades/train/39.jpg\n",
      "facades/train/62.jpg\n",
      "facades/train/270.jpg\n",
      "facades/train/271.jpg\n",
      "facades/train/272.jpg\n",
      "facades/train/273.jpg\n",
      "facades/train/274.jpg\n",
      "facades/train/275.jpg\n",
      "facades/train/276.jpg\n",
      "facades/train/277.jpg\n",
      "facades/train/278.jpg\n",
      "facades/train/279.jpg\n",
      "facades/train/28.jpg\n",
      "facades/train/280.jpg\n",
      "facades/train/281.jpg\n",
      "facades/train/282.jpg\n",
      "facades/train/283.jpg\n",
      "facades/train/284.jpg\n",
      "facades/train/285.jpg\n",
      "facades/train/286.jpg\n",
      "facades/train/287.jpg\n",
      "facades/train/288.jpg\n",
      "facades/train/289.jpg\n",
      "facades/train/351.jpg\n",
      "facades/train/352.jpg\n",
      "facades/train/353.jpg\n",
      "facades/train/354.jpg\n",
      "facades/train/355.jpg\n",
      "facades/train/356.jpg\n",
      "facades/train/357.jpg\n",
      "facades/train/358.jpg\n",
      "facades/train/359.jpg\n",
      "facades/train/36.jpg\n",
      "facades/train/360.jpg\n",
      "facades/train/361.jpg\n",
      "facades/train/362.jpg\n",
      "facades/train/363.jpg\n",
      "facades/train/364.jpg\n",
      "facades/train/365.jpg\n",
      "facades/train/366.jpg\n",
      "facades/train/367.jpg\n",
      "facades/train/368.jpg\n",
      "facades/train/369.jpg\n",
      "facades/train/37.jpg\n",
      "facades/train/63.jpg\n",
      "facades/train/64.jpg\n",
      "facades/train/65.jpg\n",
      "facades/train/66.jpg\n",
      "facades/train/67.jpg\n",
      "facades/train/68.jpg\n",
      "facades/train/69.jpg\n",
      "facades/train/7.jpg\n",
      "facades/train/70.jpg\n",
      "facades/train/71.jpg\n",
      "facades/train/72.jpg\n",
      "facades/train/73.jpg\n",
      "facades/train/74.jpg\n",
      "facades/train/75.jpg\n",
      "facades/train/76.jpg\n",
      "facades/train/77.jpg\n",
      "facades/train/78.jpg\n",
      "facades/train/79.jpg\n",
      "facades/train/8.jpg\n",
      "facades/train/80.jpg\n",
      "facades/train/81.jpg\n",
      "facades/train/82.jpg\n",
      "facades/train/83.jpg\n",
      "facades/train/84.jpg\n",
      "facades/train/85.jpg\n",
      "facades/train/86.jpg\n",
      "facades/train/87.jpg\n",
      "facades/train/88.jpg\n",
      "facades/train/89.jpg\n",
      "facades/train/9.jpg\n",
      "facades/train/90.jpg\n",
      "facades/train/91.jpg\n",
      "facades/train/92.jpg\n",
      "facades/train/93.jpg\n",
      "facades/train/94.jpg\n",
      "facades/train/95.jpg\n",
      "facades/train/96.jpg\n",
      "facades/train/97.jpg\n",
      "facades/train/98.jpg\n",
      "facades/train/99.jpg\n",
      "facades/train/128.jpg\n",
      "facades/train/129.jpg\n",
      "facades/train/13.jpg\n",
      "facades/train/130.jpg\n",
      "facades/train/131.jpg\n",
      "facades/train/132.jpg\n",
      "facades/train/133.jpg\n",
      "facades/train/134.jpg\n",
      "facades/train/135.jpg\n",
      "facades/train/136.jpg\n",
      "facades/train/137.jpg\n",
      "facades/train/138.jpg\n",
      "facades/train/139.jpg\n",
      "facades/train/14.jpg\n",
      "facades/train/140.jpg\n",
      "facades/train/141.jpg\n",
      "facades/train/142.jpg\n",
      "facades/train/143.jpg\n",
      "facades/train/144.jpg\n",
      "facades/train/145.jpg\n",
      "facades/train/146.jpg\n",
      "facades/train/147.jpg\n",
      "facades/train/148.jpg\n",
      "facades/train/149.jpg\n",
      "facades/train/15.jpg\n",
      "facades/train/150.jpg\n",
      "facades/train/151.jpg\n",
      "facades/train/152.jpg\n",
      "facades/train/153.jpg\n",
      "facades/train/154.jpg\n",
      "facades/train/191.jpg\n",
      "facades/train/192.jpg\n",
      "facades/train/193.jpg\n",
      "facades/train/194.jpg\n",
      "facades/train/195.jpg\n",
      "facades/train/196.jpg\n",
      "facades/train/197.jpg\n",
      "facades/train/198.jpg\n",
      "facades/train/199.jpg\n",
      "facades/train/2.jpg\n",
      "facades/train/20.jpg\n",
      "facades/train/200.jpg\n",
      "facades/train/201.jpg\n",
      "facades/train/202.jpg\n",
      "facades/train/203.jpg\n",
      "facades/train/204.jpg\n",
      "facades/train/205.jpg\n",
      "facades/train/206.jpg\n",
      "facades/train/207.jpg\n",
      "facades/train/208.jpg\n",
      "facades/train/209.jpg\n",
      "facades/train/21.jpg\n",
      "facades/train/210.jpg\n",
      "facades/train/211.jpg\n",
      "facades/train/212.jpg\n",
      "facades/train/213.jpg\n",
      "facades/train/214.jpg\n",
      "facades/train/215.jpg\n",
      "facades/train/216.jpg\n",
      "facades/train/217.jpg\n",
      "facades/train/218.jpg\n",
      "facades/train/219.jpg\n",
      "facades/train/22.jpg\n",
      "facades/train/220.jpg\n",
      "facades/train/247.jpg\n",
      "facades/train/248.jpg\n",
      "facades/train/249.jpg\n",
      "facades/train/25.jpg\n",
      "facades/train/250.jpg\n",
      "facades/train/251.jpg\n",
      "facades/train/252.jpg\n",
      "facades/train/253.jpg\n",
      "facades/train/254.jpg\n",
      "facades/train/255.jpg\n",
      "facades/train/256.jpg\n",
      "facades/train/257.jpg\n",
      "facades/train/258.jpg\n",
      "facades/train/259.jpg\n",
      "facades/train/26.jpg\n",
      "facades/train/260.jpg\n",
      "facades/train/261.jpg\n",
      "facades/train/262.jpg\n",
      "facades/train/263.jpg\n",
      "facades/train/264.jpg\n",
      "facades/train/265.jpg\n",
      "facades/train/266.jpg\n",
      "facades/train/267.jpg\n",
      "facades/train/268.jpg\n",
      "facades/train/269.jpg\n",
      "facades/train/330.jpg\n",
      "facades/train/331.jpg\n",
      "facades/train/332.jpg\n",
      "facades/train/333.jpg\n",
      "facades/train/334.jpg\n",
      "facades/train/335.jpg\n",
      "facades/train/336.jpg\n",
      "facades/train/337.jpg\n",
      "facades/train/338.jpg\n",
      "facades/train/339.jpg\n",
      "facades/train/34.jpg\n",
      "facades/train/340.jpg\n",
      "facades/train/341.jpg\n",
      "facades/train/342.jpg\n",
      "facades/train/343.jpg\n",
      "facades/train/344.jpg\n",
      "facades/train/345.jpg\n",
      "facades/train/346.jpg\n",
      "facades/train/347.jpg\n",
      "facades/train/348.jpg\n",
      "facades/train/349.jpg\n",
      "facades/train/35.jpg\n",
      "facades/train/290.jpg\n",
      "facades/train/291.jpg\n",
      "facades/train/292.jpg\n",
      "facades/train/293.jpg\n",
      "facades/train/294.jpg\n",
      "facades/train/295.jpg\n",
      "facades/train/296.jpg\n",
      "facades/train/297.jpg\n",
      "facades/train/298.jpg\n",
      "facades/train/299.jpg\n",
      "facades/train/3.jpg\n",
      "facades/train/30.jpg\n",
      "facades/train/300.jpg\n",
      "facades/train/301.jpg\n",
      "facades/train/302.jpg\n",
      "facades/train/303.jpg\n",
      "facades/train/304.jpg\n",
      "facades/train/305.jpg\n",
      "facades/train/306.jpg\n",
      "facades/train/307.jpg\n",
      "facades/train/371.jpg\n",
      "facades/train/372.jpg\n",
      "facades/train/373.jpg\n",
      "facades/train/374.jpg\n",
      "facades/train/375.jpg\n",
      "facades/train/376.jpg\n",
      "facades/train/377.jpg\n",
      "facades/train/378.jpg\n",
      "facades/train/379.jpg\n",
      "facades/train/38.jpg\n",
      "facades/train/380.jpg\n",
      "facades/train/381.jpg\n",
      "facades/train/382.jpg\n",
      "facades/train/383.jpg\n",
      "facades/train/384.jpg\n",
      "facades/train/385.jpg\n",
      "facades/train/386.jpg\n",
      "facades/train/387.jpg\n",
      "facades/train/388.jpg\n",
      "facades/train/389.jpg\n",
      "facades/val/\n",
      "facades/val/30.jpg\n",
      "facades/val/50.jpg\n",
      "facades/val/73.jpg\n",
      "facades/val/1.jpg\n",
      "facades/val/10.jpg\n",
      "facades/val/100.jpg\n",
      "facades/val/11.jpg\n",
      "facades/val/12.jpg\n",
      "facades/val/13.jpg\n",
      "facades/val/14.jpg\n",
      "facades/val/15.jpg\n",
      "facades/val/16.jpg\n",
      "facades/val/17.jpg\n",
      "facades/val/18.jpg\n",
      "facades/val/19.jpg\n",
      "facades/val/2.jpg\n",
      "facades/val/20.jpg\n",
      "facades/val/21.jpg\n",
      "facades/val/22.jpg\n",
      "facades/val/23.jpg\n",
      "facades/val/24.jpg\n",
      "facades/val/25.jpg\n",
      "facades/val/26.jpg\n",
      "facades/val/27.jpg\n",
      "facades/val/28.jpg\n",
      "facades/val/29.jpg\n",
      "facades/val/3.jpg\n",
      "facades/val/51.jpg\n",
      "facades/val/52.jpg\n",
      "facades/val/53.jpg\n",
      "facades/val/54.jpg\n",
      "facades/val/55.jpg\n",
      "facades/val/56.jpg\n",
      "facades/val/57.jpg\n",
      "facades/val/58.jpg\n",
      "facades/val/59.jpg\n",
      "facades/val/6.jpg\n",
      "facades/val/60.jpg\n",
      "facades/val/61.jpg\n",
      "facades/val/62.jpg\n",
      "facades/val/63.jpg\n",
      "facades/val/64.jpg\n",
      "facades/val/65.jpg\n",
      "facades/val/66.jpg\n",
      "facades/val/67.jpg\n",
      "facades/val/68.jpg\n",
      "facades/val/69.jpg\n",
      "facades/val/7.jpg\n",
      "facades/val/70.jpg\n",
      "facades/val/71.jpg\n",
      "facades/val/72.jpg\n",
      "facades/val/74.jpg\n",
      "facades/val/75.jpg\n",
      "facades/val/76.jpg\n",
      "facades/val/77.jpg\n",
      "facades/val/78.jpg\n",
      "facades/val/79.jpg\n",
      "facades/val/8.jpg\n",
      "facades/val/80.jpg\n",
      "facades/val/81.jpg\n",
      "facades/val/82.jpg\n",
      "facades/val/83.jpg\n",
      "facades/val/84.jpg\n",
      "facades/val/85.jpg\n",
      "facades/val/86.jpg\n",
      "facades/val/87.jpg\n",
      "facades/val/88.jpg\n",
      "facades/val/89.jpg\n",
      "facades/val/9.jpg\n",
      "facades/val/90.jpg\n",
      "facades/val/91.jpg\n",
      "facades/val/92.jpg\n",
      "facades/val/93.jpg\n",
      "facades/val/94.jpg\n",
      "facades/val/95.jpg\n",
      "facades/val/96.jpg\n",
      "facades/val/97.jpg\n",
      "facades/val/98.jpg\n",
      "facades/val/99.jpg\n",
      "facades/val/31.jpg\n",
      "facades/val/32.jpg\n",
      "facades/val/33.jpg\n",
      "facades/val/34.jpg\n",
      "facades/val/35.jpg\n",
      "facades/val/36.jpg\n",
      "facades/val/37.jpg\n",
      "facades/val/38.jpg\n",
      "facades/val/39.jpg\n",
      "facades/val/4.jpg\n",
      "facades/val/40.jpg\n",
      "facades/val/41.jpg\n",
      "facades/val/42.jpg\n",
      "facades/val/43.jpg\n",
      "facades/val/44.jpg\n",
      "facades/val/45.jpg\n",
      "facades/val/46.jpg\n",
      "facades/val/47.jpg\n",
      "facades/val/48.jpg\n",
      "facades/val/49.jpg\n",
      "facades/val/5.jpg\n"
     ]
    }
   ],
   "source": [
    "!bash ./datasets/download_pix2pix_dataset.sh facades"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "gdUz4116xhpm"
   },
   "source": [
    "# Pretrained models\n",
    "\n",
    "Download one of the official pretrained models with:\n",
    "\n",
    "-   `bash ./scripts/download_pix2pix_model.sh [edges2shoes, sat2map, map2sat, facades_label2photo, and day2night]`\n",
    "\n",
    "Or add your own pretrained model to `./checkpoints/{NAME}_pretrained/latest_net_G.pt`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "GC2DEP4M0OsS"
   },
   "outputs": [],
   "source": [
    "!bash ./scripts/download_pix2pix_model.sh facades_label2photo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "yFw1kDQBx3LN"
   },
   "source": [
    "# Training\n",
    "\n",
    "-   `python train.py --dataroot ./datasets/facades --name facades_pix2pix --model pix2pix --direction BtoA`\n",
    "\n",
    "Change the `--dataroot` and `--name` to your own dataset's path and model's name. Use `--gpu_ids 0,1,..` to train on multiple GPUs and `--batch_size` to change the batch size. Add `--direction BtoA` if you want to train a model to transfrom from class B to A."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "0sp7TCT2x9dB"
   },
   "outputs": [],
   "source": [
    "!python train.py --dataroot ./datasets/facades --name facades_pix2pix --model pix2pix --direction BtoA"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "9UkcaFZiyASl"
   },
   "source": [
    "# Testing\n",
    "\n",
    "-   `python test.py --dataroot ./datasets/facades --direction BtoA --model pix2pix --name facades_pix2pix`\n",
    "\n",
    "Change the `--dataroot`, `--name`, and `--direction` to be consistent with your trained model's configuration and how you want to transform images.\n",
    "\n",
    "> from https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix:\n",
    "> Note that we specified --direction BtoA as Facades dataset's A to B direction is photos to labels.\n",
    "\n",
    "> If you would like to apply a pre-trained model to a collection of input images (rather than image pairs), please use --model test option. See ./scripts/test_single.sh for how to apply a model to Facade label maps (stored in the directory facades/testB).\n",
    "\n",
    "> See a list of currently available models at ./scripts/download_pix2pix_model.sh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "mey7o6j-0368"
   },
   "outputs": [],
   "source": [
    "!ls checkpoints/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "uCsKkEq0yGh0"
   },
   "outputs": [],
   "source": [
    "!python test.py --dataroot ./datasets/facades --direction BtoA --model pix2pix --name facades_label2photo_pretrained"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "OzSKIPUByfiN"
   },
   "source": [
    "# Visualize"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "9Mgg8raPyizq"
   },
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "\n",
    "img = plt.imread('./results/facades_label2photo_pretrained/test_latest/images/100_fake_B.png')\n",
    "plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "0G3oVH9DyqLQ"
   },
   "outputs": [],
   "source": [
    "img = plt.imread('./results/facades_label2photo_pretrained/test_latest/images/100_real_A.png')\n",
    "plt.imshow(img)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "ErK5OC1j1LH4"
   },
   "outputs": [],
   "source": [
    "img = plt.imread('./results/facades_label2photo_pretrained/test_latest/images/100_real_B.png')\n",
    "plt.imshow(img)"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "collapsed_sections": [],
   "include_colab_link": true,
   "name": "pix2pix",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
